package cn.gjculture.shopping.api.dao;

import cn.gjculture.shopping.api.entity.Activity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ActivityDao {
    @Insert("insert into activity(activityId,activityName,activityDesc,adImage,insertTime,updateTime,startTime,endTime,authorId) " +
            "values(#{activityId},#{activityName},#{activityDesc},#{adImage},#{insertTime},#{updateTime},#{startTime},#{endTime},#{authorId})")
    int insert(Activity activity);

    @Select("select * from activity")
    List<Activity> query();

    @Select("select * from activity where (select unix_timestamp(now())) > startTime and (select unix_timestamp(now()))<endTime and `status`=0")
    List<Activity> queryValidActivity();

    @Select("select * from activity where activityId=#{activityId}")
    Activity queryById(String activityId);
    @Select("select goodsTypeId from activitygoodstype where activityId=#{activityId}")
    List<String> queryGoodsTypeIds(String activityId);
    @Select("select goodsId from activitygoods where activityId=#{activityId}")
    List<String> queryGoodsIds(String activityId);

    @Delete("delete from activitygoodstype where activityId=#{activityId}")
    int deleteGoodsType(String activityId);
    @Delete("delete from activitygoods where activityId=#{activityId}")
    int deleteGoods(String activityId);
}
